package com.central.utils.es

import org.apache.commons.pool2.impl.{GenericObjectPool, GenericObjectPoolConfig}
import org.elasticsearch.client.RestHighLevelClient

object ElasticSearchPoolUtil {
  private val poolConfig = new GenericObjectPoolConfig
  poolConfig.setMaxTotal(8)
  private val poolFactory = new EsClientPoolFactory
  private val pool = new GenericObjectPool(poolFactory, poolConfig)

  def getClinet() = {
    val highLevelClient = pool.borrowObject()
    highLevelClient
  }

  def returnClinet(clinet:RestHighLevelClient)={
    pool.returnObject(clinet)
  }
}
